<?php

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO menu (id, judul_m, link_m, desk_m, sortir_m, parent_m, kemana, tipe_layout) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['id'], "int"),
                       GetSQLValueString($_POST['judul_m'], "text"),
                       GetSQLValueString($_POST['link_m'], "text"),
                       GetSQLValueString($_POST['desk_m'], "text"),
                       GetSQLValueString($_POST['sortir_m'], "int"),
                       GetSQLValueString($_POST['parent_m'], "int"),
                       GetSQLValueString($_POST['kemana'], "int"),
                       GetSQLValueString($_POST['layout'], "int"));

  mysql_select_db($database_konek, $konek);
  $Result1 = mysql_query($insertSQL, $konek) or die(mysql_error());

 ?>
  
   <script language="javascript">
    <!--
          alert('Add Page Success')
      window.location = "home.php?page=page";
      
    --></script>
  <?php
}


mysql_select_db($database_konek, $konek);
$query_data_menu = "SELECT * FROM menu ORDER BY id DESC";
$data_menu = mysql_query($query_data_menu, $konek) or die(mysql_error());
$row_data_menu = mysql_fetch_assoc($data_menu);
$totalRows_data_menu = mysql_num_rows($data_menu);
?>

<div class="content-text clearfix">
    <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
      <table align="center">
        <tr valign="baseline">
          <td align="left" valign="top" nowrap="nowrap"><strong>Judul Menu :</strong></td>
          <td><input type="text" name="judul_m" value="" size="32" class="form-control" /></td>
        </tr>
        <tr valign="baseline">
          <td align="left" valign="top" nowrap="nowrap"><strong>Go to : </strong></td>
          <td>
            <label>
              <input type="radio" name="kemana" value="1" id="kemana_0" checked="checked" />
              This Page</label> 
            <label>
              <input type="radio" name="kemana" value="0" id="kemana_1" />
              Link URL</label>
          </td>
        </tr>
        <tr valign="baseline">
          <td align="left" valign="top" nowrap="nowrap"><strong>Link Menu :</strong></td>
          <td><input type="text" name="link_m" value="" size="32" class="form-control" /></td>
        </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="left" valign="top"><strong>Deskripsi Meta :</strong></td>
          <td><textarea name="desk_m" cols="50" rows="5" class="form-control"></textarea></td>
        </tr>
        <tr valign="baseline">
          <td align="left" valign="top" nowrap="nowrap"><strong>Sortir :</strong></td>
          <td><input type="text" name="sortir_m" value="" size="32" class="form-control" /></td>
        </tr>
        <tr valign="baseline">
          <td align="left" valign="top" nowrap="nowrap"><strong>Parent Menu:</strong></td>
          <td><select name="parent_m" class="form-control" >
            <option value="0" <?php if (!(strcmp(0, $row_data_menu['']))) {echo "selected=\"selected\"";} ?>>None</option>
            <?php
			if($totalRows_data_menu>0){
do {  
?>
            <option value="<?php echo $row_data_menu['id']?>"<?php if (!(strcmp($row_data_menu['id'], $row_data_menu['']))) {echo "selected=\"selected\"";} ?>><?php echo $row_data_menu['judul_m']?></option>
            <?php
} while ($row_data_menu = mysql_fetch_assoc($data_menu));
  $rows = mysql_num_rows($data_menu);
  if($rows > 0) {
      mysql_data_seek($data_menu, 0);
	  $row_data_menu = mysql_fetch_assoc($data_menu);
  }
			}
?>
          </select></td>
        </tr>
        <tr valign="baseline">
          <td align="left" valign="top" nowrap="nowrap"><strong>Layout :</strong></td>
          <td><select name="layout" class="form-control" >
          <?php include "../g-template/".$row_admin['template']."/config/layout.php";
		  $a=1;
		  $b=1; 
		  for($j=1;$j<=$jumlah_layout;$j++){
			echo "<option value='".$a++."'> ".$layout[$b++]."</option>"; 
		  }
		  ?>
          
          </select>
          </td>
        </tr>
        <tr valign="baseline">
          <td align="left" valign="top" nowrap="nowrap">&nbsp;</td>
          <td><input type="submit" value="Submit" id="status-update-btn" class="btn btn-primary pull-right" /></td>
        </tr>
      </table>
      <input type="hidden" name="id" value="<?php echo $totalRows_data_menu+1 ?>" />
      <input type="hidden" name="MM_insert" value="form1" />
    </form>
</div>
</div>
  </div>

<?php

mysql_free_result($data_menu);
?>
